package com.mahao.util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.xml.bind.DatatypeConverter;

public class Base64ToImg {
	
	public static void base64ToImg(String data,String imgPath) {
		 
		   try {
		            byte[] bytes = DatatypeConverter.parseBase64Binary(data);
		            for (int i = 0; i< bytes.length;i++) {
		                if(bytes[i] < 0) {
		                    bytes[i] +=256;
		                }
		            }
		            String decodeJPG = imgPath;
		            File decodedFile = new File(decodeJPG);
		            decodedFile.createNewFile();
		            
		            OutputStream out = new FileOutputStream(decodedFile);
		            out.write(bytes);
		            out.flush();
		            out.close();
		        } catch (FileNotFoundException e) {
		            // TODO Auto-generated catch block
		            e.printStackTrace();
		        } catch (IOException e) {
		            // TODO Auto-generated catch block
		            e.printStackTrace();
		        }
		   
		}
}
